# Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

set(example bluetooth-hci-bridge)
set(supported_platforms corstone-300 corstone-310)
set(supported_rtoses cmsis-rtx cmsis-freertos)

foreach(platform IN LISTS supported_platforms)
    get_target_platform_variables(${platform})
    foreach(rtos IN LISTS supported_rtoses)
        get_target_rtos_variables(${rtos})

        set(EXAMPLE_TITLE "Bluetooth HCI bridge example")

        set(EXAMPLE_BUILD_EXECUTABLE "__build/iotsdk-example-bluetooth-hci-bridge.elf")
        set(EXAMPLE_RUN_COMMAND_VHT "```sh\r\n${PLATFORM_VHT} -a ${EXAMPLE_BUILD_EXECUTABLE}\r\n```")
        set(EXAMPLE_RUN_COMMAND_FVP "*Note: **It is not possible to run this example using an Ecosystem FVP. Please use the FVP available through AVH.**")
        set(example_dir ${EXAMPLES_OUTPUT_DIR}/${example}/${rtos}/${platform})

        configure_file(CMakeLists.txt.in ${example_dir}/CMakeLists.txt @ONLY)
        configure_file(${CMSIS_PACK_PLATFORM_CONFIG} ${example_dir}/cmsis-pack-platform.cmake @ONLY)
        configure_file(intro.md.in ${example_dir}/intro.md @ONLY)
        configure_file(outro.md.in ${example_dir}/outro.md @ONLY)
        file(STRINGS ${example_dir}/intro.md EXAMPLE_INTRO NEWLINE_CONSUME)
        file(STRINGS ${example_dir}/outro.md EXAMPLE_OUTRO NEWLINE_CONSUME)
        configure_file(${README_TEMPLATE_FILE} ${example_dir}/README.md @ONLY)
        configure_file(${LINKER_SCRIPT_GCC} ${example_dir}/gcc.ld @ONLY)
        configure_file(${LINKER_SCRIPT_ARM} ${example_dir}/armclang.sct @ONLY)
        configure_file(ci/test.sh.in ${example_dir}/ci/test.sh @ONLY)

        file(COPY
            main.c
            ci
            nimble-user-config.h
            DESTINATION ${example_dir}
        )

        file(REMOVE
            ${example_dir}/intro.md
            ${example_dir}/outro.md
            ${example_dir}/ci/test.sh.in
        )

        if(rtos STREQUAL "cmsis-freertos")
            file(COPY freertos-config DESTINATION ${example_dir})
        endif()
    endforeach()
endforeach()
